其他
TSG CTF 2020 Reverse-ing
本文为看雪论坛优秀文章
看雪论坛作者ID:CrackM
$ file reversing
reversing: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped
file = open('reversing', 'rb')
output = open('reversing_deobfuscated', 'wb')
original = file.read()
content = bytearray(original)
patched = bytearray(original)
SHELLCODE = 0x1BA
START = 0xE5
JMP_RBX_OPCODE = [0xFF, 0xD3]
def save(from_offset, to_offset):
for i in range(from_offset, to_offset):
patched[i] = content[i]
def reverse():
# for ( index = 106LL; index >= 0; --index )
# {
# opcode = *(shellcode - index);
# *(shellcode - index) = *(start + index);
# *(start + index) = opcode;
# }
#
for i in range(106, 0, -1):
opcode = content[SHELLCODE - i]
content[SHELLCODE - i] = content[START + i]
content[START + i] = opcode
SAVE_OFFSET = START
for IP in range(START, SHELLCODE):
# Check if the opcode is `jmp rbx`
if content[IP] == JMP_RBX_OPCODE[0] and content[IP + 1] == JMP_RBX_OPCODE[1]:
# Save the instructions that have been executed
save(SAVE_OFFSET, IP + 2)
SAVE_OFFSET = IP + 2
# Patch the `jmp rbx` instructions, since we don't need them anymore.
patched[IP] = 0x90
patched[IP + 1] = 0x90
reverse()
# Write to the output file
#
output.write(patched)
.~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
| 48 mov cl, BYTE PTR [rsi+rdx*1] |
| 53 xor cl, BYTE PTR [rdx+0x600194] |
| 61 add cl, BYTE PTR [rdx+0x600194] |
| 69 or rdi, rcx |
| 74 dec dl |
| 78 jns 0x600171 <_start+140> |
|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
| 140 mov cl, BYTE PTR [rsi+rdx*1] |
| 145 xor cl, BYTE PTR [rdx+0x600194] |
| 153 add cl, BYTE PTR [rdx+0x600194] |
| 161 or rdi, rcx |
| 166 sub dl, 0x1 |
| 171 jns 0x600115 <_start+48> |
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
1. 执行48语句,cl = input[0]。
2. 切换上下文,loc_600194=[0x48, 0x80, 0x46, 0xba, 0xa5, 0xd3...],记为A。
3. 执行XOR cl= input[0] ^ 0x48。
4. 切换上下文,loc_600194=[0xE4, 0xD3, 0xFF, 0x05, 0x0F, 0x6B, 0x7C.....],记为B。
5. 执行加法, cl= (input[36] ^ 0xdb + 0xe4)&0xFF。
6. 计算$rdi = $rdi | cl。
7. ......这样循环1-6步,计算直到字符串末尾(计算过程中注意数据切换)。
8. 判断是$rdi是不是0,如果是0,输出字符“correct”,否则输出“wrong”。
Input[i] ^ B[i] + A[i] = 0;i为偶数。
X1 = [0x48, 0x80, 0x46, 0xba, 0xa5, 0xd3, 0xff, 0xc0, 0x31, 0x48, 0x1e, 0x65, 0x32, 0xa4, 0x88, 0xd3,0xff, 0xe6, 0x89, 0x48, 0x5f, 0x7a, 0x84, 0x3b, 0xd3, 0xff, 0xd2, 0x31, 0x48, 0x4e, 0x36, 0xc9,0xc5, 0xcf, 0x22, 0x32, 0x58,]
X2 = [0xe4, 0xd3, 0xff, 0x05, 0x0f, 0x6b, 0x7c, 0x13, 0xff, 0xca, 0xd3, 0xff, 0xff, 0x31, 0x48, 0x72,0x63, 0x2b, 0x19, 0x8c, 0xd3, 0xff, 0x25, 0xb2, 0x19, 0x5e, 0x61, 0xfb, 0xc1, 0xd3, 0xff, 0x00,0x60, 0x00, 0xb0, 0xbb, 0xdb,]
flag = ""
for i in range(0x25):
if i%2==0:
f = (-X2[i]^X1[i])%0x100
else:
f = (-X1[i]^X2[i])%0x100
flag += chr(f)
print(flag)
看雪ID:CrackM
https://bbs.pediy.com/user-560717.htm
*本文由看雪论坛 CrackM 原创,转载请注明来自看雪社区。
推荐文章++++
好书推荐